package com.wenx.restcamel;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

import java.util.Date;

public class AppHttpGet extends RouteBuilder {

    public static void main(String[] args) throws Exception {
        CamelContext context = new DefaultCamelContext(); // 1. 创建 CamelContext.
        context.addRoutes(new AppHttpGet());
        context.setTracing(true);
        context.start(); // 4. 启动CamelContext.
        Thread.sleep(Integer.MAX_VALUE);  // 为了保持CamelContext处于工作状态，这里需要sleep主线程
        context.stop(); // 最后停止CamelContext
    }

    public void configure() throws Exception {
        Date date = new Date();
        boolean bool = true;
        from("timer:foo?repeatCount=1")
                //.to("http://blog.csdn.net/kkdelta/article/details/7242112")
                //.to("http://10.10.5.213:8080/dmp")
                .setHeader(Exchange.HTTP_METHOD,constant("GET"))
                .setHeader(Exchange.HTTP_QUERY,constant("id=123&name=abc&date="+date+"&bool="+bool))
                .to("http://localhost:8080/demo/hello5")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        exchange.getOut().setHeader("name","wenxing");
                        System.out.println("header "+exchange.getIn().getHeaders());
                        System.out.println("header "+exchange.getOut().getHeaders());
                    }
                });
    }

    /*
    * from("quartz://report?cron=10 * * * * ?&stateful=true"),配置一个quartz Job,
    * 每隔10秒发送一个HTTP request,将收到的内容保存为文件.
    * 这里的http url可以是任何可以访问的http url,
    * 如果在http访问时候需要代理可以这么配置:
    * "http://www.baidu.com?proxyHost=proxy.xxx.com&proxyPort=8080"
    * */
}
